package com.runtu.domain.trade.service.lock.factory;

import com.runtu.domain.trade.model.entity.GroupBuyActivityEntity;
import com.runtu.domain.trade.model.entity.TradeLockRuleCommandEntity;
import com.runtu.domain.trade.model.entity.TradeLockRuleFilterBackEntity;
import com.runtu.domain.trade.service.lock.filter.ActivityUsabilityRuleFilter;
import com.runtu.domain.trade.service.lock.filter.UserTakeLimitRuleFilter;
import com.runtu.types.design.framework.link.model2.LinkArmory;
import com.runtu.types.design.framework.link.model2.chain.BusinessLinkedList;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * @ClassName TradeRuleFilterFactory
 * @Description  交易规则过滤工厂
 * 工厂 就是为了编排责任链的一些东西 然后返回对应的一个实体化对象的作用
 * @date 2025/8/11 12:33
 * @Version 1.0
 */
@Slf4j
@Service
public class TradeLockRuleFilterFactory {

    //这个链路可以注入到tradeorderService中去使用
    @Bean("tradeRuleFilter")
    public BusinessLinkedList<TradeLockRuleCommandEntity, TradeLockRuleFilterFactory.DynamicContext, TradeLockRuleFilterBackEntity> tradeRuleFilter(ActivityUsabilityRuleFilter activityUsabilityRuleFilter, UserTakeLimitRuleFilter userTakeLimitRuleFilter) {
        LinkArmory<TradeLockRuleCommandEntity, TradeLockRuleFilterFactory.DynamicContext, TradeLockRuleFilterBackEntity> linkArmory =
                new LinkArmory<>("锁单 交易规则过滤链",activityUsabilityRuleFilter,userTakeLimitRuleFilter);

        return linkArmory.getLogicLink();
    }

    /**
     * 定义一个上下文 不好维护的信息 可以放到上下文中 可以一直串联
     * 方便我们随时到不同的结点去调用
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class DynamicContext{
        private GroupBuyActivityEntity groupBuyActivity;
    }
}
